/*
 * Licensed by the Bunie Developmentgroup
 */
package handler;

import gui.BarGraphPanel;
import gui.PieChartPanel;
import gui.UserAdministrationPanel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * Repainst the bargraph if the user clicks on the bargraph tab 
 * @author Joep Kemperman
 */
public class TabbedPaneListener implements ChangeListener {

	BarGraphPanel barGraphPanel;
	PieChartPanel pieChartPanel;
	
	/**
	 * Constructor
	 * @param barGraphPanel Bargraphpanel used as referention for repainting.
	 */
	public TabbedPaneListener(BarGraphPanel barGraphPanel, PieChartPanel pieChartPanel) {
		this.barGraphPanel = barGraphPanel;
		this.pieChartPanel = pieChartPanel;
	}
	
	@Override
	public void stateChanged(ChangeEvent e) {
		if (e.getSource() instanceof JTabbedPane) {
			JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
			
			if (tabbedPane.getSelectedComponent() instanceof UserAdministrationPanel) { // UserAdminPanel is selected
				UserAdministrationPanel userAdminPanel = (UserAdministrationPanel) tabbedPane.getSelectedComponent();
				userAdminPanel.refresh();
			}
		}
		System.out.println("Change!");
	}
	
}
